package condominio.servlet.visita;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import condominio.excepcion.DAOExcepcion;
import condominio.negocio.GestionVisitas;

/**
 * Servlet implementation class VisitaInsertarServlet
 */
@WebServlet("/VisitaInsertarServlet")
public class VisitaInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public VisitaInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
		String dnivisita = request.getParameter("DNI");
		String nombrevisita = request.getParameter("Nombre");
		String Vivienda = request.getParameter("vivienda");
		String fecha = request.getParameter("Fecha");
		
				
		GestionVisitas negocio = new GestionVisitas();
		try {
			negocio.insertar(Integer.parseInt(dnivisita),nombrevisita,Integer.parseInt(Vivienda),fecha);
			RequestDispatcher rd = request.getRequestDispatcher("visitante_insert_ok.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error_visita.jsp");
			rd.forward(request, response);
		}
		
	}
	
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
